TARGET=xstub_dahua
ROOT=..
BUILD_DIR= ./build

_VERSION=
_LIB=
ifeq ($(_VERSION),release)
BUILDNAME=$(TARGET)
CXXFLAGS += -O3 -D_USEDAEMON 
else
BUILDNAME=$(TARGET)_debug 
#CXXFLAGS += -g -D_DUMP_AUDIO
CXXFLAGS += -g -O3
LIBS += 
endif

CXXFLAGS += -I./utils -I $(ROOT)/common/include -I ./new -I .

ifeq ($(_LIB),debug)
LDFLAGS  += -L ./debug_lib -L../common/lib
LIBS     += -lresolv -lsvcommon $(ROOT)/common/lib/libcl.a -ldhdvr -ldhnetsdk -ldhparser -Wl /usr/lib/libstdc++.so.5 -Wl ./debug_lib/libiconv.so.2
else
LDFLAGS  += -L ./new -L../common/lib
LIBS     += -lresolv -lsvcommon $(ROOT)/common/lib/libcl.a -ldhdvr -ldhnetsdk -ldhparser -ldhTPLayer -Wl /usr/lib/libstdc++.so.5 
endif

SUBDIRS=utils

CPP_FILES=$(wildcard *.cpp)
HPP_FILES=$(wildcard *.hpp)
OBJ_FILES=$(patsubst %.cpp,%.o,$(CPP_FILES))


.PHONY: all clean submake
all: init $(BUILDNAME) 

init:
	mkdir -p ./build

$(OBJ_FILES):$(CPP_FILES) $(HPP_FILES)
	$(CXX) -c $(CXXFLAGS) $(patsubst %.o,%.cpp,$@) -o $(BUILD_DIR)/$@

submake:$(SUBDIRS)
	make -C $< _VERSION=$(_VERSION)
	
$(BUILDNAME): submake $(OBJ_FILES) 
	$(CXX) $(LDFLAGS) $(LIBS) -o  $@ $(BUILD_DIR)/*.o
 

clean:
	rm -rf $(BUILD_DIR)/*.o xstub_dahua xstub_dahua_debug

ut_sel:
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LIBS) -o $@ unit_test/test_selector.cpp selector.cpp
